import { ElTreeSelect } from 'element-plus'
// 航线类型
export enum WaylineType {
  NormalWaypointWayline = 0, // 普通航点航线
  AccurateReshootingWayline = 1 // 精准复拍航线
}

export interface WaylineFile {
  id: string
  name: string
  drone_model_key: any
  payload_model_keys: string[]
  template_types: WaylineType[]
  update_time: number
  user_name: string
}

export interface Overlap {
  inclinedCameraOverlapH: string
  orthoCameraOverlapW: string
  inclinedCameraOverlapW: string
  orthoCameraOverlapH: string
}

export interface LinearRing {
  coordinates: string
}

export interface OuterBoundaryI {
  linearRing: LinearRing
}

export interface Polygon {
  outerBoundaryIs: OuterBoundaryI
}

export interface PointInfo {
  margin: string
  overlap: Overlap
  caliFlightEnable: string
  shootType: string
  inclinedFlightSpeed: string
  polygon: Polygon
  inclinedGimbalPitch: string
  efficiencyFlightModeEnable: string
  direction: string
  ellipsoidHeight: string
  height: string
  Point: any
  executeHeight: string
}

export interface IActionActuatorFuncParam {
  gimbalPitchRotateAngle: string;
  gimbalPitchRotateEnable: string;
  gimbalRollRotateEnable: string;
  gimbalYawRotateAngle: string;
  gimbalYawRotateEnable: string;
  payloadPositionIndex: string;
  gimbalRollRotateAngle: string;
  gimbalRotateTime: string;
  gimbalRotateTimeEnable: string;
  gimbalHeadingYawBase: string;
  gimbalRotateMode: string;
}

export interface IAction {
  actionActuatorFuncParam: IActionActuatorFuncParam;
  actionActuatorFunc: string;
  actionId: string;
}

export interface IActionTrigger {
  actionTriggerParam: string;
  actionTriggerType: string;
}

export interface IActionGroup {
  actionTrigger: IActionTrigger;
  actionGroupStartIndex: string;
  actionGroupId: string;
  action: IAction[];
  actionGroupMode: string;
  actionGroupEndIndex: string;
}
// 定义嵌套的接口类型
export interface IPoint {
  coordinates: string; // 点的坐标
}

export interface IWaypointGimbalHeadingParam {
  waypointGimbalPitchAngle: string;
  waypointGimbalYawAngle: string;
}

export interface IWaypointTurnParam {
  waypointTurnMode: string; // 航点转弯模式
  waypointTurnDampingDist: string; // 航点转弯阻尼距离
}

export interface IWaypointHeadingParam {
  waypointHeadingAngleEnable: string;
  waypointPoiPoint: string; // 航点 POI 点
  waypointHeadingPoiIndex: string; // 航点 POI 索引
  waypointHeadingPathMode: string; // 航点路径模式
  waypointHeadingAngle: string; // 航点角度
  waypointHeadingMode: string; // 航点模式
}
export interface IOrthophotoPointInfo {
  waypointTurnParam: IWaypointTurnParam;
  isRisky: string;
  waypointHeadingParam: IWaypointHeadingParam;
  executeHeight: string;
  useStraightLine: string;
  waypointWorkType: string;
  waypointSpeed: string;
  waypointGimbalHeadingParam: IWaypointGimbalHeadingParam;
  index: string;
  Point: IPoint;
  actionGroup: IActionGroup;
}

export interface ILinearRing {
  coordinates: string; // 线性环的坐标
}

export interface IOuterBoundaryIs {
  LinearRing: ILinearRing; // 外部边界的线性环
}

export interface IPolygon {
  outerBoundaryIs: IOuterBoundaryIs; // 多边形的外部边界
}

export interface IOverlap {
  inclinedCameraOverlapH: string; // 倾斜相机重叠高度
  orthoCameraOverlapW: string; // 正射相机重叠宽度
  inclinedCameraOverlapW: string; // 倾斜相机重叠宽度
  orthoCameraOverlapH: string; // 正射相机重叠高度
}

// 定义 RootObject 类型
export interface RootObject {
  isRisky: string; // 是否危险
  useGlobalHeight: string; // 是否使用全局高度
  useStraightLine: string; // 是否使用直线
  index: string; // 索引
  Point: IPoint; // 点信息
  ellipsoidHeight: string; // 椭球高度
  waypointTurnParam: IWaypointTurnParam; // 航点转弯参数
  useGlobalTurnParam: string; // 是否使用全局转弯参数
  waypointHeadingParam: IWaypointHeadingParam; // 航点航向参数
  useGlobalHeadingParam: string; // 是否使用全局航向参数
  waypointSpeed: string; // 航点速度
  useGlobalSpeed: string; // 是否使用全局速度
  height: string; // 高度
}

// 定义 templatePointInfo 的数据类型
export interface ITemplatePointInfo {
  isLookAtSceneSet: string; // 是否设置查看场景
  margin: string; // 边距
  smartObliqueEnable: string; // 智能倾斜启用
  elevationOptimizeEnable: string; // 高程优化启用
  facadeWaylineEnable: string; // 立面航线启用
  ellipsoidHeight: string; // 椭球高度
  overlap: IOverlap; // 重叠参数
  quickOrthoMappingEnable: string; // 快速正射映射启用
  caliFlightEnable: string; // 校准飞行启用
  shootType: string; // 拍摄类型
  Polygon: IPolygon; // 多边形信息
  efficiencyFlightModeEnable: string; // 效率飞行模式启用
  direction: string; // 方向
  height: string; // 高度
  Point: IPoint; // 点信息
}

export type PointType = { Lon: number; Lat: number; height: number }
export interface IWailinePointList {
  waypointTurnParam: IWaypointTurnParam;
  isRisky: string;
  waypointHeadingParam: IWaypointHeadingParam;
  executeHeight: string;
  useStraightLine: string;
  waypointWorkType: string;
  waypointSpeed: string;
  waypointGimbalHeadingParam: IWaypointGimbalHeadingParam;
  index: string;
  Point: IPoint;
  actionGroup: IActionGroup;
}

export interface IInclinePointInfo {
  duration: number;
  wailinePointList: IWailinePointList[];
  distance: number;
  photoNum: number;
}

// 最终联合类型
export type TemplateTypes = 0 | 1 | 2;

export interface BaseWayLineFile {
  name: string
  task_names: string
  id: string
  sign: string
  favorited: boolean
  drone_model_key: string
  payload_model_keys: string[]
  template_types: TemplateTypes[]
  object_key: string
  user_name: string
  templatePointInfo: ITemplatePointInfo[]
  waylinePointInfo: PointInfo[]
  inclinePointInfo: IInclinePointInfo[]
  orthophotoPointInfo: IOrthophotoPointInfo[]
  distance: number
  duration: number
  photo_num: number
  update_time: number
  create_time: number
  takeOffRefPoint: string
}
// 条件映射类型
type PointInfoCondition<T extends readonly TemplateTypes[]> = {
  template_types: T
} & (T extends Array<infer U> ?
  (0 extends U ? { templatePointInfo: ITemplatePointInfo[] } : {}) &
  (0 extends U ? { waylinePointInfo: PointInfo[] } : {}) &
  (1 extends U ? { orthophotoPointInfo: IOrthophotoPointInfo[] } : {})
  : never)
export type WayLineFile<T extends readonly TemplateTypes[]> = BaseWayLineFile & PointInfoCondition<T>

// 提取 ElTreeSelect 的实例类型
export type ElTreeSelectInstance = InstanceType<typeof ElTreeSelect>;

export const droneOptions = [
  {
    value: '全部机型',
    label: '全部机型'
  },
  {
    value: '0-67-0,0-67-1',
    label: '经纬M30系列',
    children: [
      {
        value: '0-67-0',
        label: '经纬 M30'
      },
      {
        value: '0-67-1',
        label: '经纬 M30 T'
      }
    ]
  },
  {
    value: '0-77-0,0-77-1',
    label: 'Mavic 3 行业系列',
    children: [
      {
        value: '0-77-0',
        label: 'Mavic 3E'
      },
      {
        value: '0-77-1',
        label: 'Mavic 3T'
      }
    ]
  },
  {
    value: '0-91-0,0-91-1',
    label: 'Matrice 3D 系列',
    children: [
      {
        value: '0-91-0',
        label: 'Mavic 3E'
      },
      {
        value: '0-91-0',
        label: 'Mavic 3T'
      }
    ]
  },
  {
    value: '0-99-0,0-99-1',
    label: 'Matrice 4 行业系列',
    children: [
      {
        value: '0-99-0',
        label: 'Matrice 4E'
      },
      {
        value: '0-99-1',
        label: 'Matrice 4T'
      }
    ]
  },
  {
    value: '0-100-0,0-100-1',
    label: 'Matrice 4D 系列',
    children: [
      {
        value: '0-100-0',
        label: 'Matrice 4D'
      },
      {
        value: '0-100-1',
        label: 'Matrice 4TD'
      }
    ]
  }
]

export interface WaylineDataInfo {
  distance: string;
  duration: string;
  photo_num: number;
  area?: string;
  pointNun?: number;
}
